package com.xbongbong.paas.service.stage;

import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 阶段处理工厂
 * @author 李少杰
 * @version v1.0.0
 * @date 2021/11/23 11:06
 */
@Component
public class StageHandleFactory {
    @Resource
    private Map<Integer, StageHandle> stageHandleMap;

    public StageHandle getStageHandle(Integer saasMark, Integer businessType) {
        if (Objects.equals(SaasMarkEnum.PAAS.getCode(), saasMark)) {
            return stageHandleMap.get(XbbRefTypeEnum.PAAS.getCode());
        } else {
            XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
            switch (xbbRefTypeEnum) {
                case CUSTOMER_MANAGEMENT:
                case CUSTOMER:
                case CUSTOMER_STAGE:
                    return stageHandleMap.get(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
                case CLUE:
                case ALL_CLUE:
                case CLUE_STAGE:
                    return stageHandleMap.get(XbbRefTypeEnum.CLUE.getCode());
                case SALES_OPPORTUNITY:
                case ALL_OPPORTUNITY:
                case SALE_STAGE:
                    return stageHandleMap.get(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode());
                case CONTRACT:
                    // 合同阶段是个Paas字段
                    return stageHandleMap.get(XbbRefTypeEnum.PAAS.getCode());
                default:
                    return stageHandleMap.get(XbbRefTypeEnum.PAAS.getCode());
            }
        }
    }
}
